from __future__ import annotations

from typing import Any

import gdb  # type: ignore

from .base import Adapter
from .utils import value_to_python


class PrimitiveAdapter(Adapter):
    name = "primitive"

    def supports(self, gdb_value: gdb.Value) -> bool:
        return gdb_value.type.code in {
            gdb.TYPE_CODE_INT,
            gdb.TYPE_CODE_FLT,
            gdb.TYPE_CODE_BOOL,
            gdb.TYPE_CODE_ENUM,
            gdb.TYPE_CODE_CHAR,
        }

    def serialize(self, gdb_value: gdb.Value) -> Any:
        return value_to_python(gdb_value)